#ifndef __QUEUE_H_
#define __QUEUE_H_

#define QUEUE_MAXSIZE  64 //队的最大容量

typedef struct
{
    int data[QUEUE_MAXSIZE];
    int isOperator[QUEUE_MAXSIZE];
    int head; //出队位置
    int tail; //入队位置
}queue;

//初始化队,清空队 
int queueInit(queue *q)
{
    if(q != NULL)
    {
        int i;
        q->head=0;
        q->tail=0;
        for(i=0;i<QUEUE_MAXSIZE;i++)
        {
            q->isOperator[i]=0;
        }
        return 1;
    }
    return 0;
}

//判断队是否为空 
int queueIsEmpty(queue *q)
{
    if(q->head==q->tail)
    {
        return 1;
    }
    return 0;
}

//判断队是否已满
int queueIsFull(queue *q)
{
    int head = q->head;
    int tail = q->tail;
    if(tail == QUEUE_MAXSIZE-1)
    {
        tail = 0;
    }
    else
    {
        tail = tail + 1;
    }
    if(head == tail)
    {
        return 1;
    }
    return 0;
}

//入队 
int queuePush(queue *q, int value,int type)//若栈未满，将元素x入栈s 中；否则提示出错信息
{
    if(queueIsFull(q))
    {
        printf("队列已满\n");
        return 0;
    }
    q->data[q->tail] = value;
    q->isOperator[q->tail] = type;
    if(q->tail == QUEUE_MAXSIZE-1)
    {
        q->tail = 0;
    }
    else
    {
        q->tail = q->tail + 1;
    }
    return 1;
}

//出队 
int queuePop(queue *q, int *value, int *type)
{
    if(queueIsEmpty(q))
    {
        printf("队列已空\n");
        return 0;
    }
    *value = q->data[q->head];
    *type = q->isOperator[q->head];
    q->isOperator[q->head]=0;
    if(q->head == QUEUE_MAXSIZE-1)
    {
        q->head = 0;
    }
    else
    {
        q->head = q->head + 1;
    }
    return 1;
}

#endif
